package com.automannn.dubbo.withSpringBoot;

import com.automannn.dubbo.api.HelloService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ApplicationContext;

/**
 * @author chenkh
 * @time 2021/8/5
 */
@EnableDubbo
@SpringBootApplication(exclude = {JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class})
public class DubboRunWithSpringBootConsumer {

    @DubboReference
    private HelloService helloService;

    public void call(){
        this.helloService.sayHi("automannn");
        System.out.println("==================");
        System.out.println("微服务调用成功!");
    }



    public static void main(String[] args) {
        ApplicationContext context= new SpringApplicationBuilder()
                .sources(DubboRunWithSpringBootConsumer.class)
                .web(WebApplicationType.NONE)
                .run(args);
       DubboRunWithSpringBootConsumer consumer= context.getBean(DubboRunWithSpringBootConsumer.class);
       consumer.call();

    }
}
